using System;
using GeneralDFS.DataEntity.Nodes;

namespace GeneralDFS.BusinessLogical.RemoteObject
{
    public partial class NameNodeRemoteObject
    {
        /// <summary>
        /// Called by the predecessor to a remote node, this acts as a dual heartbeat mechanism and more importantly
        /// notification mechanism between predecessor and successor.
        /// </summary>
        /// <param name="node">A ChordNode instance indicating who the calling node (predecessor) is.</param>
        public void Notify(NameNodeInfo node)
        {
            // if the node has absolutely no predecessor, take
            // the first one it finds
            if (this.Predecessor == null)
            {
                this.Predecessor = node;
                return;
            }

            if (GeneralDFS.Common.DFSUtils.IsIDInRange(node.ID, this.Predecessor.ID, this.ID))
            {
                this.Predecessor = node;
                return;
            }
        }
    }
}
